package com.benyi.util;

import java.util.HashMap;

/**
 * 同一线程内部共享的变量
 * @author admin
 *
 */
public class LocalVarys {
	
	private static ThreadLocal<HashMap<String,Object>> local = new ThreadLocal<HashMap<String,Object>>();
	
	public static void set(String key,Object v){
		if(v==null) {
			return;
		}
		HashMap<String,Object> m=local.get();
		if(m==null){
			m = new HashMap<String,Object>();
			local.set(m);
		}
		m.put(key, v);
	}
	
	
	public static Object get(String key){
		HashMap<String,Object> m=local.get();
		Object v=null;
		if(m != null){
			v=m.get(key);
		}
		return v;
	}
	
	public static void clear(){
		HashMap<String,Object> m=local.get();
		if(m!=null){
			m.clear();
		}
		local.set(null);
	}
	
	public static Object remove(String key){
		HashMap<String,Object> m=local.get();
		Object v=null;
		if(m != null){
			v=m.remove(key);
		}
		return v;
	} 
}
